# dates = [
#     '0808',
#     '0811','0812','0813','0814','0815',
#     '0818','0819','0820','0821','0822',
#     '0825','0826','0827','0828','0829',
    # ]
dates = [
    # '0901','0902','0903','0904','0905',
    # '0908','0909','0910',
    "0911",'0912',
    '0915','0916','0917'
    ]
categories = ['coat' , 'sweater' , 'leather']
# categories = ['sweater' , 'leather']
# categories = ['coat']

from tqdm import tqdm
import os,shutil
from util_for_os import ose,osj

dir = '/mnt/nas/datasets/diction'
IMAGES_DIR = osj( dir , f'images_front_back' )

get_clo_front_back = lambda category,date : osj( dir , f'{category}{date}_img_front_back' )

total_count = 0

for category in categories:
    for date in dates:

        if date >= '0826' and category == 'leather':
            continue

        src_dir = get_clo_front_back(category, date)
        names_path = osj(src_dir, 'names.txt')
        assert ose(src_dir),src_dir
        assert ose(names_path),names_path

for category in categories:
    for date in dates:


        if date >= '0826' and category == 'leather':
            continue

        src_dir = get_clo_front_back(category, date)
        names_path = osj(src_dir, 'names.txt')
        if not ose(names_path):
            print(f"names.txt not found: {names_path}")
            continue
        with open(names_path, 'r') as f:
            lines = f.readlines()

        count_save = 0
        for line in tqdm(lines):
            img_name = line.strip()
            if not img_name or not img_name.lower().endswith('.jpg'):
                continue
            src_img_path = osj(src_dir, img_name)
            dst_img_path = osj(IMAGES_DIR, img_name)
            if not ose(src_img_path):
                print(f"Image not found: {src_img_path}")
                continue
            # 确保目标文件夹存在
            os.makedirs(IMAGES_DIR, exist_ok=True)
            shutil.copy2(src_img_path, dst_img_path)

            count_save += 1
        total_count += count_save
print('process num : ',total_count)



'''
bash code >

dates=("0808" "0811" "0812" "0813" "0814" "0815" "0818" "0819" "0820")
categories=("coat")

for date in "${dates[@]}"; do
    for category in "${categories[@]}"; do
        bash restore.sh "/mnt/nas/datasets/diction/${category}${date}_front_back"
    done
done
'''